<template>
<!-- 收付费作业-强制转账页面 -->
    <div class="fillcontain">
        <el-form :model="searchParams" :rules="rules" ref="ruleForm" label-width="100px" class="search_container">
            <el-row>
                <el-col :span="6">
                    <el-form-item label="保单号码" prop="chdrNum">
                        <el-input v-model="searchParams.chdrNum" placeholder="请输入" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="受理号" prop="applNum">
                        <el-input v-model="searchParams.applNum" placeholder="请输入" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="公司" prop="companyNum">
                        <el-input v-model="searchParams.companyNum" placeholder="请输入" clearable></el-input>
                    </el-form-item>
                </el-col>
                <!-- 分支 -->
                <el-col :span="6">
                    <el-form-item label="Branch" prop="branch">
                        <el-input v-model="searchParams.branchNum" placeholder="请输入" clearable></el-input>
                    </el-form-item>
                </el-col>
                <!-- 是否转账  -->
                <el-col :span="6">
                    <el-form-item label="转账" prop="isTransfer">
                        <el-select v-model="searchParams.isTransfer" placeholder="请选择" >
                            <el-option v-for="item in isTransferOption" :key="item.value" :label="item.label" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="次数" prop="timers">
                        <el-input v-model="searchParams.timers" placeholder="请输入" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="6" class="text_center">
                    <el-button type="primary" icon="el-icon-search" @click="subGetList"></el-button>
                    <el-button type="primary" plain  icon="el-icon-refresh" @click="resetSearch"></el-button>
                </el-col>
            </el-row>
        </el-form>
        <div class="contain">
          <div class="table_container">
            <el-table v-loading="loading" :data="tableData" highlight-current-row header-cell-class-name="table-header-class" style="width:100%">
                <el-table-column
                        min-width="60"
                        property="companyNum"
                        label="公司号"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        min-width="120"
                        property="branchNum"
                        label="Branch"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        min-width="120"
                        property="applNum"
                        label="受理号"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        min-width="120"
                        property="chdrNum"
                        label="保单号"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <!-- CYQ:20200203-收付费作业-强制转账-转账状态转化 -->
                <el-table-column
                        min-width="120"
                        property="isTransfer"
                        label="转账"
                        align='center'
                        show-overflow-tooltip :formatter="transferStatus">
                </el-table-column>
                <!-- 次數 -->
                <el-table-column
                        min-width="120"
                        property="timers"
                        label="次数"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        min-width="120"
                        property="procTranDate"
                        label="Proc Tran Date"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                        min-width="120"
                        property="userName"
                        label="用户"
                        align='center'
                        show-overflow-tooltip>
                </el-table-column>
                <el-table-column
                min-width="120"
                    property="batchNum"
                    label="批次"
                    align='center'
                    show-overflow-tooltip>
                </el-table-column>
                <el-table-column 
                 min-width="180"
                   property="systemDate"
                   label="系统日期"
                   align='center'
                   show-overflow-tooltip>
                </el-table-column>
                <el-table-column 
                 min-width="100"
                    fixed="right"
                   label="操作"
                   align='center'>
                   <template slot-scope="scope">
                        <!-- <el-button type="text" size="small" @click="compulsoryUpdateGo(scope.row)">修改</el-button> -->
                        <span class="operationIcon" @click="compulsoryUpdateGo(scope.row)">
                             <el-tooltip class="item" effect="light" content="修改" placement="top">
                                <i class="el-icon-edit"></i>
                            </el-tooltip>
                        </span>
                    </template>
                </el-table-column>
            </el-table>
           <el-row>
                <el-col :span="24">
                    <div class="pagination">
                        <el-pagination
                            background
                            v-if='paginations.total > 0'
                            :page-sizes="paginations.pageSizes"
                            :page-size="paginations.pageSize"
                            :layout="paginations.layout"
                            :total="paginations.total"
                            :current-page='paginations.pageIndex'
                            @current-change='handleCurrentChange'
                            @size-change='handleSizeChange'>
                        </el-pagination>
                    </div>
                </el-col>
            </el-row>
          </div>
        </div>
        <!-- 弹框你好啊 -->
        <el-dialog
            title="修改"
            :visible.sync="compulsoryDialog"
            width="50%"
            center @close="closeDialog">
            <el-form ref="form" :model="form"  label-width="120px">
              <el-row>
                  <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">公司</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input  v-bind:disabled="true" v-model="form.companyNum" placeholder="公司号"></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">Branch</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input v-bind:disabled="true" v-model="form.branchNum" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">受理号</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input v-bind:disabled="true" v-model="form.applNum" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">保单号</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input v-bind:disabled="true" v-model="form.chdrNum" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">转账</label>
                        </el-col>
                         <el-col :span="16">
                             <el-select v-model="form.isTransfer" placeholder="" filterable @change="checkTransferStatus(form)">
                                <el-option
                                    v-for="item in isTransferOption"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                                </el-option>
                            </el-select>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">次数</label>
                        </el-col>
                         <el-col :span="16">
                            <el-input v-bind:disabled="true" v-model="form.timers" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">Proc Tran Date</label>
                        </el-col>
                         <el-col :span="16">
                            <el-input  v-bind:disabled="true" v-model="form.procTranDate" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">用户</label>
                        </el-col>
                         <el-col :span="16">
                            <el-input  v-bind:disabled="true" v-model="form.userName" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">批次</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input  v-bind:disabled="true" v-model="form.batchNum" placeholder=""></el-input>
                         </el-col>
                    </el-col>
                    <el-col :span="12" class="common-box">
                        <el-col :span="6" class="common-lab">
                             <label class="labelName">系统日期</label>
                        </el-col>
                         <el-col :span="16">
                             <el-input  v-bind:disabled="true" v-model="form.systemDate" placeholder=""></el-input>
                         </el-col>
                    </el-col>
              </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="colseCompulsoryDialog">返 回</el-button>
                <el-button @click="updateIsTransferStatus(form)" class="Defaultbutton">保 存</el-button>
            </span>
        </el-dialog>

    </div>
</template>

<script>
    import { mapState, mapGetters } from 'vuex'
    import constant from '@/utils/constant';
    import { findforceTransferQueryList,queryAutoPayInSatatus,updateforceTransferInfo } from '@/api/selloutLock/forceTransfer';
    export default {
        data(){
            return {
                valueDate:'',
                compulsoryDialog:false,//默认隐藏弹框
                // 查询条件
                rules:{
                    chdrNum:[],
                    applNum:[],
                    companyNum:[],
                    branchNum:[],
                    isTransfer:[],
                    timers:[]
                },
                searchParams:{
                    chdrNum:'', //客户号
                    applNum:'', //客户姓名
                    companyNum: '', //公司号码
                    branchNum:'',//分支号码
                    isTransfer:'',//转账
                    timers:''//次数
                },
                tableData: [],
                form:{},//CYQ:20200203-收付费作业-强制转账-
                loading:false,
                //需要给分页组件传的信息
                paginations: {
                    total: 0,        // 总数
                    pageIndex: 1,  // 当前位于哪页
                    pageSize: 10,   // 1页显示多少条
                    pageSizes: [5, 10, 15, 20],  //每页显示多少条
                    layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
                },
                pickerOptions1: {
                  disabledDate(time) {
                    return time.getTime() > Date.now();
                  }
                },
                isTransferOption:[{label:'是',value:'Y'},{label:'否',value:'N'}],//CYQ:收付费作业-强制转账-是否转账选项
                canUpdateStatus:false,//CYQ:收付费作业-强制转账-能否进行转账
                oldIsTransferStatus:'',//CYQ:每次打开页面后旧的转账状态
            }
        },

        created(){
//          this.getList();
        },
        mounted(){
            // this.getList();
        },
        methods: {

            //CYQ:20200304-收付费作业-强制转账-叉掉窗口
            closeDialog(){
                console.log("CYQ:20200305-强制转账-我叉掉了窗口,所以也要刷新页面数据");
                this.getList2();
            },
            //CYQ:20200206-收付费作业-触发转账修改记录
            updateIsTransferStatus(row){
                console.log("CYQ：20200206-收付费作业-强制转账-执行修改转账状态!");
                if(row.isTransfer == this.oldIsTransferStatus){
                     this.$message({
                        message: '转账状态没有改变!',
                        type: 'error'
                     });
                    return false;
                }                

                if(this.canUpdateStatus == false){
                    this.$message({
                            message:'转账状态校验不通过!',
                            type: 'error'
                        }); 
                    return false;
                }
                var newIsTransfer = row.isTransfer;
                let params = {
                    "applNum"       : row.applNum,
                    "chdrNum"       : row.chdrNum,
                    "newIsTransfer" : newIsTransfer,
                    "oldIsTransfer" : this.oldIsTransferStatus
                }
                this.$store.dispatch('loading/CHANGE_LOADING',true);
                updateforceTransferInfo(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING',false)
                    if(res.resultCode == constant.SUCCESS){
                        this.$message({
                            message: res.resultMsg,
                            type: 'success'
                        });
                        this.compulsoryDialog = false;
                        console.log("CYQ：20200206-收付费作业-强制转账-执行修改转账状态-成功!");
                        this.getList2();
                    }else{
                       this.form.isTransfer = this.oldIsTransferStatus;//无效
                    }
                }).catch(err =>{
                    this.$store.dispatch('loading/CHANGE_LOADING',false);
                })
            },
            //关闭弹窗
            colseCompulsoryDialog(row){
                this.compulsoryDialog = false;
                this.getList2();
            },

            //触发校验
            checkTransferStatus(row){
                console.log("CYQ：20200206-收付费作业-强制转账-触发检验是否可以修改!");
                var newIsTransfer = row.isTransfer;
                
                if(newIsTransfer == this.oldIsTransferStatus){
                     this.$message({
                        message: '转账状态没有改变!',
                        type: 'error'
                     });
                    return false;
                }

                //不为空
                if(newIsTransfer == null || newIsTransfer == ''){
                     this.$message({
                        message: '转账模式不为空!',
                        type: 'error'
                     });
                    return false;
                }

                let params = {
                    "applNum"       : row.applNum,
                    "branchNum"     : row.branchNum,
                    "isTransfer"    : this.oldIsTransferStatus,
                    "newIsTransfer" : newIsTransfer
                }
                this.$store.dispatch('loading/CHANGE_LOADING',true);
                queryAutoPayInSatatus(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING',false)
                    if(res.resultCode == constant.SUCCESS){
                        this.$message({
                            message: '转账状态校验成功',
                            type: 'success'
                        });
                        this.canUpdateStatus = true;
                    }else{
                       this.form.isTransfer = this.oldIsTransferStatus;//无效
                    }
                }).catch(err =>{
                    this.$store.dispatch('loading/CHANGE_LOADING',false);
                })
            },


            //修改
            compulsoryUpdateGo(row){
                this.compulsoryDialog  = true;
                this.form =row;
                this.form.procTranDate = row.procTranDate;
                this.oldIsTransferStatus = row.isTransfer;
                console.log("生产日期 :"+row.procTranDate);
            },
            
            //CYQ:20200203-收付费作业-强制转账-转账状态转化
            transferStatus(row){
                if(row.isTransfer == 'Y'){
                    return "是";
                }else if(row.isTransfer == 'N'){
                    return "否";
                }else{
                    return '';
                }
            },

            // 查询列表
            getList2(){
                this.paginations.total=0;
                this.tableData=[];
                let params = {
                    "chdrNum"     : this.searchParams.chdrNum,
                    "applNum"     : this.searchParams.applNum,
                    "companyNum"  : this.searchParams.companyNum,
                    "branchNum"   : this.searchParams.branchNum,
                    "isTransfer"  : this.searchParams.isTransfer,
                    "timers"      : this.searchParams.timers,
                    "pageSize"    : this.paginations.pageSize,
                    "pageNumber"  : this.paginations.pageIndex,
                    "orderBy"     : "",
                }
                this.$store.dispatch('loading/CHANGE_LOADING',true);
                findforceTransferQueryList(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING',false)
                    if(res.resultCode == constant.SUCCESS && res.data && res.data.list.length){
                        this.paginations.total = res.data.total;
                        this.tableData = res.data.list;
                    }
                   
                }).catch(err =>{
                    this.$store.dispatch('loading/CHANGE_LOADING',false);
                })
            },


            // 查询列表
            getList(){
                this.paginations.total=0;
                this.tableData=[];
                let params = {
                    "chdrNum"     : this.searchParams.chdrNum,
                    "applNum"     : this.searchParams.applNum,
                    "companyNum"  : this.searchParams.companyNum,
                    "branchNum"   : this.searchParams.branchNum,
                    "isTransfer"  : this.searchParams.isTransfer,
                    "timers"      : this.searchParams.timers,
                    "pageSize"    : this.paginations.pageSize,
                    "pageNumber"  : this.paginations.pageIndex,
                    "orderBy"     : "",
                }

                //校验
                if(params.applNum!='' && isNaN(params.applNum)){
                    this.$message({
                        message: '受理号必须为数字!',
                        type: 'error'
                    });
                    return false;
                }
                if(params.chdrNum!='' && isNaN(params.chdrNum)){
                    this.$message({
                        message: '保单号必须为数字!',
                        type: 'error'
                    });
                    return false;
                }
                    


                this.$store.dispatch('loading/CHANGE_LOADING',true);
                findforceTransferQueryList(params).then(res => {
                    this.$store.dispatch('loading/CHANGE_LOADING',false)
                    if(res.resultCode == constant.SUCCESS && res.data && res.data.list.length){
                        this.paginations.total = res.data.total;
                        this.tableData = res.data.list;
                        this.$message({
                            message: res.resultMsg,
                            type: 'success'
                        });
                    }
                   
                }).catch(err =>{
                    this.$store.dispatch('loading/CHANGE_LOADING',false);
                })
            },
            // 每页多少条切换
            handleSizeChange(pageSize) {
               this.paginations.pageSize = pageSize;
               this.getList();
            },
            // 上下分页
            handleCurrentChange(page) {
               this.paginations.pageIndex = page;
               this.getList();
            },
            // 根据条件查询列表
            subGetList(){
                this.paginations.pageIndex=1;
                this.getList();
            },
            // 清除查询条件
            resetSearch(){
                this.searchParams.chdrNum = '';
                this.searchParams.applNum = '';
                this.searchParams.companyNum = '';
                this.searchParams.branchNum = '';
                this.searchParams.isTransfer = '';
                this.searchParams.timers = '';
            }
        },
        computed:{
            ...mapGetters(['tags']),
            reload(){
                return this.$store.state.loading.reload;
            }
        },
        activated(){
            if(this.reload){
                this.$store.dispatch('loading/CHNAGE_RELOAD',false)
                Object.assign(this.$data, this.$options.data());
            }
        }
    }
</script>

<style lang="less" scoped>
    .fillcontain{
        padding-bottom: 0;
    }
    .contain{
        background: #fff;
        padding: 10px;
        margin-bottom: 20px;
    }
   .pagination{
       padding: 10px 20px;
       text-align: right;
   }
   .operationIcon{
        // padding: 12px;
        border:1px solid #e5e5e5;
        border-radius: 50%;
        width: 22px; 
        height: 22px;
        display: inline-block;
        cursor: pointer;
        box-shadow:0 0 3px #f9f9f9;
        .svg-icon{
            font-size: 14px;
            fill:#68a3fc;
        }
   }
   .search_container{
       padding: 20px 20px 0 20px;
   }
   .common-box{
        padding-bottom: 15px;
    }
    .common-lab{
        line-height:normal!important;
        text-align: right;
        .labelName{
            text-align: right;
        }
    }
</style>



